import requests

import settings
from utils.util_logger import logger

class UtilRequest:

    def __init__(self):
        self.session = requests.Session()
        self.bas_url = settings.BASE_HOST
        self.time_out = settings.TIMEOUT
        self.headers = {}
        self.session.headers.update(self.headers)

    def send_api(self, method: str, url: str, **kwargs):
        """发送api方法"""
        full_url = self.bas_url + url

        # 合并请求头信息
        final_headers = {**self.session.headers, **self.headers}
        
        return self.session.request(
            method=method,
            url=full_url,
            timeout=self.time_out,
            headers=final_headers,
            **kwargs
        )
